#include <UnitTest++.h>
#include <iostream>
#include <TestReporter.h>

#ifdef _DEBUG
#	pragma comment(lib,"UnitTest++_d")
#else
#	pragma comment(lib,"UnitTest++")
#endif

#include <SGF.h>
#include <mapformat.pb.h>

namespace UnitTest
{
	class SGFTestReporter:public TestReporter
	{
		bool succeeded;
	public:
		virtual ~SGFTestReporter(){}

		virtual void ReportTestStart(TestDetails const& test)
		{
			printf("%s.%s ",test.suiteName,test.testName);
			succeeded=true;
		}

		virtual void ReportTestFinish(TestDetails const& test, float secondsElapsed)
		{
			if(succeeded)
				printf("succeeds\n");
		}

		virtual void ReportFailure(TestDetails const& details, char const* failure)
		{
			succeeded=false;
			const char* errorFormat="fails\n%s:%d: error: %s\n";
			printf(errorFormat, details.filename, details.lineNumber, failure);			
		}

		virtual void ReportSummary(int totalTestCount, int failedTestCount,
											   int failureCount, float secondsElapsed)
		{
			if (failureCount > 0)
				printf("FAILURE: %d out of %d tests failed (%d failures).\n", failedTestCount, totalTestCount, failureCount);
			else
				printf("Success: %d tests passed.\n", totalTestCount);

			printf("Test time: %.2f seconds.\n", secondsElapsed);
			std::cin.get();
		}
	};
}

int main()
{
	using namespace UnitTest;
	SGFTestReporter reporter;
	TestRunner runner(reporter);
	return runner.RunTestsIf(Test::GetTestList(), NULL, True(), 0);
}